package com.mall.util;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//import java.util.logging.Filter;

/**
 * Created by xiaoyao on 2017/8/20.
 * 解决跨域请求
 */
public class Cors implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Header", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE,PUT,HEAD");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "Authentication, Origin, X-Requested-With, XRequestedWith, Content-Type, Accept, LastModified");
//        response.setHeader("Content-Type", "application/json;charset=UTF-8");

        filterChain.doFilter(servletRequest, servletResponse);
    }

    public void destroy() {

    }

}
